<template>
  <div class="hotel-room-management">
    <h1>酒店房间管理</h1>
    <div class="room-list">
      <div v-for="room in sortedRooms" :key="room.id" class="room-item">
        <h2>{{ room.name }}</h2>
        <p>类型: {{ room.type }}</p>
        <p>价格: ¥{{ room.price }}</p>
        <p>状态: {{ room.status }}</p>
        <p>入住时间: {{ room.checkIn }}</p>
        <p>退房时间: {{ room.checkOut }}</p>
        <button v-if="room.status === '空闲'" @click="checkInRoom(room.id)" class="edit-button">入住</button>
        <button v-if="room.status === '已入住'" @click="checkOutRoom(room.id)" class="delete-button">退房</button>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      rooms: [
        { id: 1, name: '房间 101', type: '单人间', price: 100, status: '空闲', checkIn: '2023-10-01', checkOut: '2023-10-05' },
        { id: 2, name: '房间 102', type: '双人间', price: 200, status: '已入住', checkIn: '2023-10-02', checkOut: '2023-10-06' },
        // 其他房间数据
      ],
    };
  },
  computed: {
    sortedRooms() {
      return this.rooms.sort((a, b) => a.id - b.id);
    },
  },
  methods: {
    checkInRoom(id) {
      const room = this.rooms.find(room => room.id === id);
      if (room) {
        room.status = '已入住';
        room.checkIn = new Date().toISOString().split('T')[0];
      }
    },
    checkOutRoom(id) {
      const room = this.rooms.find(room => room.id === id);
      if (room) {
        room.status = '空闲';
        room.checkOut = new Date().toISOString().split('T')[0];
      }
    },
  },
};
</script>

<style scoped>
.hotel-room-management {
  padding: 40px;
  font-family: 'Helvetica Neue', Arial, sans-serif;
  background: linear-gradient(135deg, #f8f9fa, #e9ecef);
  min-height: 100vh;
}

h1 {
  text-align: center;
  color: #2d3436;
  font-size: 2.8rem;
  margin-bottom: 40px;
  font-weight: 600;
  letter-spacing: 1.5px;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.1);
}

.room-list {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 25px;
  max-width: 1200px;
  margin: 0 auto;
}

.room-item {
  background: #ffffff;
  border-radius: 16px;
  padding: 25px;
  width: 320px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.08);
  transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
  position: relative;
  overflow: hidden;
}

.room-item:hover {
  transform: translateY(-5px);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.15);
}

.room-item::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, #28a745 0%, #17a2b8 100%);
}

.room-item h2 {
  color: #2d3436;
  font-size: 1.6rem;
  margin-bottom: 15px;
  font-weight: 600;
}

.room-item p {
  color: #636e72;
  font-size: 15px;
  margin: 10px 0;
  line-height: 1.5;
}

button {
  display: block;
  width: 100%;
  padding: 12px;
  margin-top: 15px;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-size: 18px;
  transition: background-color 0.3s, opacity 0.3s;
}

.edit-button {
  background-color: #28a745;
  color: white;
}

.delete-button {
  background-color: #dc3545;
  color: white;
}

button:hover {
  opacity: 0.9;
}
</style>
